import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ElderBasicVO, ElderBasicForm, ElderBasicQuery } from '@/api/nursing/elderBasic/types';

/**
 * 查询老人基础信息列表
 * @param query
 * @returns {*}
 */

export const listElderBasic = (query?: ElderBasicQuery): AxiosPromise<ElderBasicVO[]> => {
  return request({
    url: '/nursing/elderBasic/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询老人基础信息详细
 * @param elderId
 */
export const getElderBasic = (elderId: string | number): AxiosPromise<ElderBasicVO> => {
  return request({
    url: '/nursing/elderBasic/' + elderId,
    method: 'get'
  });
};

/**
 * 新增老人基础信息
 * @param data
 */
export const addElderBasic = (data: ElderBasicForm) => {
  return request({
    url: '/nursing/elderBasic',
    method: 'post',
    data: data
  });
};

/**
 * 修改老人基础信息
 * @param data
 */
export const updateElderBasic = (data: ElderBasicForm) => {
  return request({
    url: '/nursing/elderBasic',
    method: 'put',
    data: data
  });
};

/**
 * 删除老人基础信息
 * @param elderId
 */
export const delElderBasic = (elderId: string | number | Array<string | number>) => {
  return request({
    url: '/nursing/elderBasic/' + elderId,
    method: 'delete'
  });
};

/**
 * 审核老人基础信息
 * @param elderId 老人ID
 * @param reviewStatus 审核状态（1：通过，2：拒绝）
 */
export const reviewElderBasic = (elderId: string | number, reviewStatus: string) => {
  return request({
    url: `/nursing/elderBasic/review/${elderId}/${reviewStatus}`,
    method: 'put'
  });
};

/**
 * 根据姓名模糊查询老人
 * @param name 老人姓名
 */
export const getEldersByName = (name?: string): AxiosPromise<ElderBasicVO[]> => {
  return request({
    url: '/nursing/elderBasic/eldersByName',
    method: 'get',
    params: { name }
  });
};

/**
 * 根据姓名模糊查询所有老人（用于联系人验证）
 * @param name 老人姓名
 */
export const getAllEldersByName = (name?: string): AxiosPromise<ElderBasicVO[]> => {
  return request({
    url: '/nursing/elderBasic/allEldersByName',
    method: 'get',
    params: { name }
  });
};
